package com.zb.rebbitMq;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class Producer {

	private static final String QUEUE_NAME ="binbin";
	private static final ConnectionFactory factory = new ConnectionFactory();
	
	public Producer() {
		//连接工厂
				
				//配置登陆账号
				factory.setHost("106.12.222.85");
				factory.setPort(5672);
				factory.setUsername("guest");
				factory.setPassword("guest");
				factory.setVirtualHost("/");	
	}
	
	public void send() {
		//建立连接
		Connection connection = null;
		Channel channel = null;
		try {
			connection = factory.newConnection();
			channel = connection.createChannel();
			
			//申明队列
			channel.queueDeclare(QUEUE_NAME, false, false, false, null);
			String message ="小斌你好啊";
			channel.basicPublish("", QUEUE_NAME, null, message.getBytes());
			System.out.println("【send】..."+message);
		}catch (Exception e) {
			e.printStackTrace();
		}finally {
			try {
				channel.close();
				connection.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (TimeoutException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
		
	
	
	
	
	
}
